package com.gree.commom.result;

import com.gree.commom.enums.BaseResultEnum;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yangjia
 * @since 2021/7/5
 */
@Data
public class RespBean {
    /**
     * 响应状态
     */
    private Integer code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应数据
     */
    private Map<String, Object> data = new HashMap<String, Object>();

    public RespBean(){}

    public static RespBean ok(){
        RespBean respBean = new RespBean();
        respBean.setCode(BaseResultEnum.SUCCESS.getCode());
        respBean.setMessage(BaseResultEnum.SUCCESS.getMessage());
        return respBean;
    }

    public static RespBean error(){
        RespBean respBean = new RespBean();
        respBean.setCode(BaseResultEnum.ERROR.getCode());
        respBean.setMessage(BaseResultEnum.ERROR.getMessage());
        return respBean;
    }

    public static RespBean setResult(BaseResultEnum resultCodeEnum){
        RespBean respBean = new RespBean();
        respBean.setCode(resultCodeEnum.getCode());
        respBean.setMessage(resultCodeEnum.getMessage());
        return respBean;
    }

    public RespBean message(String message){
        this.setMessage(message);
        return this;
    }

    public RespBean code(Integer code){
        this.setCode(code);
        return this;
    }

    public RespBean data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public RespBean data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
